﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:converters="clr-namespace:Chem4Word.UI.Converters" mc:Ignorable="d" x:Class="Chem4Word.UI.Navigator.NavigatorItem" x:Name="navigatorItem" MinHeight="24" MinWidth="100" Width="235" Margin="0,1,0,2">
	<UserControl.Resources>
		<converters:HasImageAndIsExpandedToVisibilityConverter x:Key="hasImageAndIsExpandedToVisibilityConverter" />
		<converters:IsMouseOverHasImageToVisibilityConverter x:Key="isMouseOverAndHasImageToVisibilityConverter" />

		<Storyboard x:Key="OnMouseEnterNavigatorItem">
			<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="linkMenu" Duration="00:00:00.3" BeginTime="00:00:00" To="1.0" />
			<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="copyMenu" Duration="00:00:00.3" BeginTime="00:00:00" To="1.0" />
			<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="expander" Duration="00:00:00.3" BeginTime="00:00:00" To="1.0" />
		</Storyboard>

		<Storyboard x:Key="OnMouseLeaveNavigatorItem">
			<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="linkMenu" Duration="00:00:00" BeginTime="00:00:00" To="0.5" />
			<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="copyMenu" Duration="00:00:00" BeginTime="00:00:00" To="0.5" />
			<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="expander" Duration="00:00:00" BeginTime="00:00:00" To="0.5" />
		</Storyboard>

		<Style TargetType="{x:Type Border}">
			<Setter Property="BorderThickness" Value="1" />
			<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
			<Style.Triggers>
				<DataTrigger Binding="{Binding Path=IsSelected, ElementName=navigatorItem}" Value="True">
					<Setter Property="BorderThickness" Value="2" />
					<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style TargetType="{x:Type TextBlock}" x:Key="TitleStyle">
			<Setter Property="Margin" Value="1" />
			<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.GradientInactiveCaptionBrushKey}}" />
			<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
			<Setter Property="FontSize" Value="15" />
			<Setter Property="VerticalAlignment" Value="Center" />
			<Style.Triggers>
				<DataTrigger Binding="{Binding Path=IsSelected, ElementName=navigatorItem}" Value="True">
					<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>


		<Style TargetType="{x:Type Menu}">
			<Setter Property="Margin" Value="1" />
			<Setter Property="HorizontalAlignment" Value="Left" />
			<Setter Property="Visibility" Value="Visible" />
			<Setter Property="Opacity" Value="0.5" />
			<Style.Triggers>
				<DataTrigger Value="True" Binding="{Binding ElementName=navigatorItem, Path=IsMouseOver}">
					<Setter Property="Visibility" Value="Visible" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style TargetType="{x:Type Expander}">
			<Setter Property="Margin" Value="1" />
			<Setter Property="HorizontalAlignment" Value="Right" />
			<Setter Property="Visibility" Value="Visible" />
			<Setter Property="Opacity" Value="0.5" />
			<Setter Property="ToolTip" Value="Hide the 2D image." />
			<Style.Triggers>
				<DataTrigger Binding="{Binding ElementName=expander, Path=IsExpanded}" Value="False">
					<Setter Property="ToolTip" Value="Show the 2D image." />
				</DataTrigger>
			</Style.Triggers>
		</Style>

	</UserControl.Resources>
	<UserControl.Triggers>
		<EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="navigatorItem">
			<BeginStoryboard Storyboard="{StaticResource OnMouseEnterNavigatorItem}" />
		</EventTrigger>
		<EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="navigatorItem">
			<BeginStoryboard Storyboard="{StaticResource OnMouseLeaveNavigatorItem}" />
		</EventTrigger>
	</UserControl.Triggers>
	<Border x:Name="border">
		<Grid x:Name="grid">
			<Grid.RowDefinitions>
				<RowDefinition Height="25" />
				<RowDefinition />
			</Grid.RowDefinitions>
			<TextBlock Style="{StaticResource TitleStyle}" x:Name="title" Grid.Row="0" MouseLeftButtonDown="TitleMouseLeftButtonDown" MouseRightButtonDown="TitleMouseRightButtonDown">
				<TextBlock.ContextMenu>
					<ContextMenu x:Name="navigatorItemTitleDepictionOptionsMenu">
					</ContextMenu>
				</TextBlock.ContextMenu>
				<Run>Zone1</Run>
			</TextBlock>
			<StackPanel x:Name="stackPanel" Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right">
				<Menu x:Name="linkMenu">
					<Menu.ToolTip>
						Insert a linked copy of this Chemistry Zone
					</Menu.ToolTip>
					<MenuItem x:Name="linkMenuItem">
						<MenuItem.Header>
							<Image Source="../Resources/Images/Shortcut.png" />
						</MenuItem.Header>
					</MenuItem>
				</Menu>
				<Menu x:Name="copyMenu">
					<Menu.ToolTip>
						Insert an unlinked copy of this Chemistry Zone
					</Menu.ToolTip>
					<MenuItem x:Name="copyMenuItem">
						<MenuItem.Header>
							<Image Source="../Resources/Images/Copy.png" />
						</MenuItem.Header>
					</MenuItem>
				</Menu>
				<Expander x:Name="expander" HorizontalAlignment="Right" HorizontalContentAlignment="Right" Expanded="ExpanderExpanded" Collapsed="ExpanderCollapsed">
					<Expander.Visibility>
						<MultiBinding Converter="{StaticResource isMouseOverAndHasImageToVisibilityConverter}">
                            <Binding ElementName="navigatorItem" Path="IsMouseOver" />
                            <Binding ElementName="navigatorItem" Path="HasImage" />
						</MultiBinding>
					</Expander.Visibility>
				</Expander>
			</StackPanel>
			<Grid Grid.Row="1" x:Name="thumbnailGrid" Background="White" MouseLeftButtonDown="ThumbnailGridMouseLeftButtonDown">
				<Grid.Visibility>
					<MultiBinding Converter="{StaticResource hasImageAndIsExpandedToVisibilityConverter}">
						<Binding ElementName="navigatorItem" Path="HasImage" />
						<Binding ElementName="expander" Path="IsExpanded" />
					</MultiBinding>
				</Grid.Visibility>
			</Grid>
		</Grid>
	</Border>
</UserControl>